﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;

using SourceGrid.Cells.Editors;

namespace SourceGrid
{
    public class ExtGrid : Grid
    {
        private Dictionary<string, EditorBase> editors = new Dictionary<string, EditorBase>();

        public ExtGrid()
        {
        }

        #region Editors
        public IEnumerable<EditorBase> Editors
        {
            get { return editors.Values; }
        }

        public void AddEditor(string columnName, EditorBase editor)
        {
            if (editors.ContainsKey(columnName))
                return;

            editors.Add(columnName, editor);
        }

        public EditorBase RemoveEditor(string columnName)
        {
            if (editors.ContainsKey(columnName))
            {
                EditorBase r = editors[columnName];
                editors.Remove(columnName);
                return r;
            }
            
            return null;
        }

        public EditorBase this[string columnName]
        {
            get { return editors[columnName]; }
            set { editors.Add(columnName, value); }
        }
        #endregion

        #region Public Methods
        public void SetReadOnly()
        {
            foreach (EditorBase editor in editors.Values)
                editor.EnableEdit = false;
        }

        public void SetReadOnlyExceptColumns(string[] columns)
        {
            SetReadOnly();

            foreach (string column in columns)
                editors[column].EnableEdit = true;
        }
        #endregion
    }
}
